<?php

declare(strict_types=1);

namespace App\Api\Service;

use App\Model\Member;

class MemberService
{
    /**
     * 获取用户信息
     * @return Member
     */
    public function index(): Member
    {
        // 查询用户
        $member = Member::query()
            ->where('id', api_member_id())
            ->firstOrFail();

        return $member->setVisible(['avatar', 'nickname', 'phone']);
    }

    /**
     * 更新用户信息
     * @param array $params
     * @return void
     */
    public function update(array $params): void
    {
        // 用户
        $member = Member::query()
            ->where('id', api_member_id())
            ->firstOrFail();

        // 更新
        $member->fill($params)->save();
    }
}
